package com.baymx.anotherapp

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.baymx.anotherapp.ui.theme.TestSceneTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            TestSceneTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Greeting("Android") {
                        Button(onClick = { startService() }) {
                            Text(text = "启动服务")
                        }
                    }
                }
            }
        }
    }

    fun startService() {
        this.startService(Intent(this, FocusService::class.java))
    }
}

@Composable
fun Greeting(
    name: String,
    modifier: Modifier = Modifier,
    content: @Composable ColumnScope.() -> Unit
) {
    val state = rememberScrollState()
    Column(
        modifier = Modifier
            .background(Color.White)
            .padding(horizontal = 8.dp)
            .verticalScroll(state)
    ) {
        content()
    }

}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    TestSceneTheme {
        Greeting("Android") {
            Button(onClick = { }) {
                Text(text = "启动服务")
            }
        }
    }
}